

def cards(num):
    if num=="J":
        return 11
    elif num=="Q":
        return 12
    elif num=="K":
        return 13
    elif num=="A":
        return 14
    else:
        return int(num)

def countNums(nums,partCount,maxSameCount):
    count={}
    for num in nums:
        if count.get(num) is None:
            count[num]=0
        count[num]=count[num]+1
    if len(count.keys()) != partCount:
        return False
    return maxSameCount in count.values()

def isSantiao(nums):
    return countNums(nums,3,3)
def isHuLu(nums):
    return countNums(nums,2,3)
def isSiTiao(nums):
    return countNums(nums,2,4)
def isTonghu(colors):
    return len(set(colors))==1
def isShunzi(nums):
    if "".join(nums)=="2345A":
        return True
    for i in range(1,len(nums)):
        if cards(nums[i-1])+1!=cards(nums[i]):
            return False
    return True
arr=[list(input().split()) for i in range(0,5)]
print(arr)
def getResult():
    nums=[]
    colors=[]
    for num,color in arr:
        nums.append(num)
        colors.append(color)
    nums.sort(key=lambda x:cards(x))

    if isShunzi(nums) and isTonghu(colors):
        return 1
    elif isSiTiao(nums):
        return 2
    elif isHuLu(nums):
        return 3
    elif isTonghu(colors):
        return 4
    elif isShunzi(nums):
        return 5
    elif isSantiao(nums):
        return 6
    else:
        return 0

print(getResult())

# 4 H
# 5 S
# 6 C
# 7 D
# 8 D



